package com.example.ojcodesandbox.codesandbox;

import com.example.ojcodesandbox.impl.*;
import com.example.ojcommon.common.ExecuteCodeRequest;
import com.example.ojcommon.common.ExecuteCodeResponse;
import org.springframework.stereotype.Component;

/**
 * 代码沙箱策略类
 */
@Component
public class CodeSandboxFactory {
    public ExecuteCodeResponse execute(ExecuteCodeRequest executeCodeRequest){
        Integer language = executeCodeRequest.getLanguage();
        switch (language){
            case 1:
                JavaDockerCodeSandbox javaDockerCodeSandbox = new JavaDockerCodeSandbox();
                return javaDockerCodeSandbox.executeCode(executeCodeRequest);
            case 2:
                CDockerCodeSandbox cDockerCodeSandbox = new CDockerCodeSandbox();
                return cDockerCodeSandbox.executeCode(executeCodeRequest);
            case 3:
                CPPDockerCodeSandbox cppDockerCodeSandbox = new CPPDockerCodeSandbox();
                return cppDockerCodeSandbox.executeCode(executeCodeRequest);
            case 4:
                PythonDockerCodeSandbox pythonDockerCodeSandbox = new PythonDockerCodeSandbox();
                return pythonDockerCodeSandbox.executeCode(executeCodeRequest);
            case 5:
                GoDockerCodeSandbox goDockerCodeSandbox = new GoDockerCodeSandbox();
                return goDockerCodeSandbox.executeCode(executeCodeRequest);
            default:
                return null;
        }
    }
}
